home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2000 February / Macworld (2000-02).dmg / Games World / Hot demos! / Starbound II / AI agents / Gypsum 1.00 / Gypsum 1.00.rsrc / ss$t_146 < prev    next >
Text File  |  1999-10-30  |  2KB  |  73 lines

  1. situation space_unit
  2.    // Approach: Send all ships after the ship with the lowest shields
  3. vars
  4.    me : ship;
  5.    mx : integer;
  6.    my : integer;
  7.    i : integer;
  8.    s : ship;
  9.    low_ship : ship;
  10.    low_shield : integer;
  11.    success : boolean;
  12.    tx : integer;
  13.    ty : integer;
  14.    dist : integer;
  15.  
  16. function CheckShip(target : ship) : ship;
  17. vars
  18.    sum : integer;
  19. begin
  20.    sum := Space_fore_shield(target) +
  21.           Space_aft_shield(target) +
  22.           Space_port_shield(target) +
  23.           Space_starboard_shield(target);
  24.    if low_ship = nil then
  25.       begin
  26.          low_ship := target;
  27.          low_shield := sum;
  28.       end;
  29.    else if sum < low_shield then
  30.       begin
  31.          low_ship := target;
  32.          low_shield := sum;
  33.       end;
  34.    return Next_ship(target);
  35. end;
  36.  
  37. begin
  38.    // Get yourself
  39.    me := This_ship();
  40.    mx := Get_space_x(me);
  41.    my := Get_space_y(me);
  42.    // Activate all of your systems
  43.    i := 0;
  44.    while (i < 6) do
  45.       begin
  46.          // We don't want to turn on the self destruct system
  47.          if (Fire_system(My_race(), Space_class(me), Space_gen(me), i) <> 73) then
  48.             success := Set_fire_status(me, i, true);
  49.          i := i + 1;
  50.       end;
  51.    // Determine which ship to attack, based on lowest shields
  52.    low_ship := nil;
  53.    low_shield := 0;
  54.    s := First_ship(false);
  55.    while (s <> nil) do
  56.       s := CheckShip(s);
  57.    if low_ship <> nil then
  58.       begin
  59.          success := Set_space_target(me, low_ship);
  60.          // The ship will automatically move toward the target
  61.       end;
  62. end;
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.